package com.lin.cms.service.impl;

import java.util.List;
import org.apache.ibatis.session.RowBounds;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.lin.cms.util.Paging;
import com.lin.cms.criteria.FtpCriteria;
import com.lin.cms.domain.Ftp;
import com.lin.cms.service.FtpService;
import com.lin.cms.dao.FtpMapper;

@Service
public class FtpServiceImpl implements FtpService{
	
	@Autowired
    private FtpMapper ftpMapper;
    
	public Ftp selectByPrimaryKey(Integer ftpId){
		return ftpMapper.selectByPrimaryKey(ftpId);
	}
	
	public List<Ftp> selectByCriteria(FtpCriteria criteria){
		return ftpMapper.selectByCriteria(criteria);
	}
	
	public int deleteByPrimaryKey(Integer ftpId){
		int actualRowsAffected = 0;
		
		Ftp _oldFtp = ftpMapper.selectByPrimaryKey(ftpId);
		
		if (_oldFtp != null) {
			actualRowsAffected = ftpMapper.deleteByPrimaryKey(ftpId);
		}
		
		return actualRowsAffected;
	}
	
	public int deleteByCriteria(FtpCriteria criteria){
		int actualRowsAffected = 0;
		
		List<Ftp> _oldFtp = ftpMapper.selectByCriteria(criteria);
		
		if (_oldFtp.size() != 0) {
			actualRowsAffected = ftpMapper.deleteByCriteria(criteria);
		}
		
		return actualRowsAffected;
	}
	
	public int insert(Ftp ftp){
		return ftpMapper.insert(ftp);
	}
	
	public int updateByPrimaryKeySelective(Ftp ftp){
		int actualRowsAffected = 0;
		
		int advertisingId = ftp.getFtpId();

		Ftp _oldFtp = ftpMapper.selectByPrimaryKey(advertisingId);
		
		if (_oldFtp != null) {
			actualRowsAffected = ftpMapper.updateByPrimaryKeySelective(ftp);
		}
		
		return actualRowsAffected;
	}
	
	public int updateByPrimaryKey(Ftp ftp){
		int actualRowsAffected = 0;
		
		int advertisingId = ftp.getFtpId();

		Ftp _oldFtp = ftpMapper.selectByPrimaryKey(advertisingId);
		
		if (_oldFtp != null) {
			actualRowsAffected = ftpMapper.updateByPrimaryKey(ftp);
		}
		
		return actualRowsAffected;
	}
	
	public List<Ftp> selectByPage(FtpCriteria criteria) {
		int totalResults = ftpMapper.countByCriteria(criteria);
		Paging paging = criteria.getPaging();
		paging.setTotalResults(totalResults);
		
		return ftpMapper.selectByPage(criteria,new RowBounds(paging.getFirstResult(),paging.getMaxResults()));
	}
	
	public int countByCriteria(FtpCriteria criteria){
		return ftpMapper.countByCriteria(criteria);
	}
	
}
